package shuashuami.hb.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.util.List;

import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.glid.GlidUtil;

/**
 * Created by Administrator on 2017/6/20.
 */

public class ComplaintAdatper extends BaseAdapter {
    private LayoutInflater inflater;
    private int selectedPosition = -1;
    private boolean shape;

    private List<String> list;

    private GlidUtil glidUtil;

    public ComplaintAdatper(Context context, List<String> list) {
        this.list = list;
        inflater = LayoutInflater.from(context);
        glidUtil = new GlidUtil(context);
    }

    public class ViewHolder {
        public ImageView image;
        public ImageView imageDelete;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_add_photo, parent,
                    false);
            holder = new ViewHolder();
            holder.image = (ImageView) convertView
                    .findViewById(R.id.item_add_photo_img);
            holder.imageDelete = (ImageView) convertView
                    .findViewById(R.id.item_delete_photo_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position != list.size() - 1) {
            glidUtil.uploadImage(list.get(position), R.mipmap.ssm_icon_127, holder.image);
            holder.imageDelete.setVisibility(View.VISIBLE);
        } else {
            glidUtil.uploadImage("", R.mipmap.ssm_icon_127, holder.image);
            holder.imageDelete.setVisibility(View.GONE);

        }
        holder.imageDelete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                list.remove(position);
                notifyDataSetChanged();
            }
        });
        return convertView;
    }

}
